const qcloud = require('../../vendor/qcloud-weapp-client-sdk/index.js')
const config = require('../../config.js')
const utils = require('../../utils.js')

//获取应用实例
const app = getApp()

Page({
  data: {
    offsetH: 0, //获取屏幕高度
    list:[],
    content:'',
    cpcId:'',
    replyList:[],
    likeList:[],
    type:'',
    isUser:false
  },

  // 全局捕获
  bindViewTap(event) {
    if (event.target.id != 'cart') {
      this.selectComponent("#cart").bindViewTap(event)
    }
  },

  getobtainCardDetail(id) {
    utils.ajaxFn({
      url: config.service.obtainCardDetail,
      body: { 'cpcId': id },
      callback: (data) => {
        let obj = data.cardDTO
        obj['timeString'] = utils.GetDateStr(obj['createTime'])
        // app.globalData.uId
        this.setData({
          isUser: app.globalData.uId == data.cardDTO.uId
        })

        this.setData({
          likeList: data.cardLikeDTOs
        })

        this.setData({
          list: Array.of(obj)
        })

        this.setData({
          replyList: data.cardReplyDTOs
        })
      }
    })
  },

  bindKeyInput(e){
    this.setData({
      content: e.detail.value
    })
  },

  createCardReplyFn() {
    if (this.data.content == '') {
      wx.showModal({
        title: '提示',
        content: "回复内容不能为空"
      }) 
      return false;
    }
    utils.ajaxFn({
      url: config.service.createCardReply,
      body: { 
        'cpcId': this.data.cpcId,
        'content': this.data.content
      },
      callback: (data) => {
        this.setData({
          content:''
        })
        this.getobtainCardDetail(this.data.cpcId)
      }
    })
  },
  // createCardReply
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // app.globalData.clockRouter = true
    
    this.setData({
      cpcId: options.cpcId
    })

    this.setData({
      type: options.type
    })

    this.getobtainCardDetail(options.cpcId)

    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          offsetH: res.windowHeight
        })
      }
    })
    
  }
})